#! /usr/bin/env python
#coding=utf-8
import simplejson as json

"""
c = {"foo": ["bar", "baz"]}
a = JsonCode()
d = a.EnCode(c)
print d

print a.DECode(d)
"""


class JsonCode:

    def DECode(self, jsde):
        if len(jsde)>0:
            try:
                dc = json.JSONDecoder().decode(jsde)
                return dc
            except:
                return None
        else:
            return None

    def EnCode(self, jsen):
        if type(jsen) is dict or type(jsen) is list or type(jsen) is tuple :
            try:                
                en = json.JSONEncoder().encode(jsen)
                return en
            except:
                return None
        else:
            return None
